Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.

Handle saving of product with no variants specified - #389

Merged
tanema merged 1 commit into
Shopify:masterfrom
rnovacek:fix-product-without-variants
Jun 8, 2020
Merged

tanema merged 1 commit into
Shopify:masterfrom
rnovacek:fix-product-without-variants

Conversation

@rnovacek

@rnovacek rnovacek commented Jun 4, 2020

Copy link
Copy Markdown
Contributor

Shopify API allows not setting all the attributes when changing a resource. It can be used as optimization to speed up things if some parts of a resource doesn't change.

Common scenario is to prevent variants update when saving product as there can be up to 100 variants per product and saving all takes a long time.

Recent update to delete inventory_quantity and old_inventory_quantity of variants when saving product broke the ability to delete variants to prevent them from saving. It was working fine in version 7.0.0.

This PR adds a check if the variants are defined on a product before attempt to delete inventory_quantity and old_inventory_quantity when saving.

@ghost ghost added the cla-needed label Jun 4, 2020
@rnovacek

rnovacek commented Jun 4, 2020

Copy link
Copy Markdown
Contributor Author

I've signed the CLA, but I don't know how to refresh it...

@ghost ghost removed the cla-needed label Jun 8, 2020
@tanema
tanema merged commit 7f892c7 into Shopify:master Jun 8, 2020
@tanema

tanema commented Jun 8, 2020

Copy link
Copy Markdown

Thanks!

@rnovacek
rnovacek deleted the fix-product-without-variants branch June 8, 2020 18:44
@beetree

beetree commented Jul 28, 2020

Copy link
Copy Markdown

I believe there's an issue with this PR. It throws an error when loading a product, editing it and then saving it. Longer discussion here.

Reproduce using:

Dockerfile:

FROM python:3.8.5
RUN pip install ShopifyAPI
ADD main.py /

main.py (example from here):

import shopify

keys = {
    "API_KEY": "XXX",
    "PASSWORD": "XXX"
}

shop_url = "https://%s:%s@XXX.myshopify.com/admin/api/2020-07" % (keys["API_KEY"], keys["PASSWORD"])
shopify.ShopifyResource.set_site(shop_url)

product = shopify.Product()
product.title = "Shopify Logo T-Shirt"
print(product.id)
product.save()

When running, this throws the error:

Traceback (most recent call last):
  File "main.py", line 17, in <module>
    product.save()
  File "/usr/local/lib/python3.8/site-packages/shopify/resources/product.py", line 39, in save
    if 'variants' in self.product.attributes:
  File "/usr/local/lib/python3.8/site-packages/pyactiveresource/activeresource.py", line 917, in __getattr__
    raise AttributeError(name)
AttributeError: product

@ernesto-butto

Copy link
Copy Markdown

Hello! So I'm back working with the same code, and the issue is still here but in another form. The default stable package at the moment, 8.0.1 does not let me create a product as documented. See bellow

API_VERSION = '2020-07'

2020-08-01_13h06_05

2020-08-01_13h05_14

If I go back to version !pip install ShopifyAPI==8.0.0 and API_VERSION = '2020-04' I get the original error, which I can bypass by adding new_product.variants = [] before saving a new product.

It seems to me that you should test the documented code for creating a new product before releasing a new api version, since its a critical blocker use case, or maybe I'm doing something wrong?

I hope this report is useful, and thank you for the API

@beetree

beetree commented Aug 3, 2020

Copy link
Copy Markdown

@rnovacek , any chance you can take a look at this issue? There are multiple reports of it by now.
Thanks!

tanema pushed a commit that referenced this pull request Aug 13, 2020
Amended pull request #389 to allow saving of products with no variants

This branch had an error being deployed

1 failed deployment
pypi — 288b30be Deployed Apr 9, 2024 by shopify-shipit[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants